/*
 * =====================================================================================
 *
 *       Filename:  test_unique_ptr.cpp
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  12/12/2010 12:06:21 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Chen Ken (Ken), zlchen.ken@gmail.com
 *        Company:  EMC
 *
 * =====================================================================================
 */

#include <memory>
#include <iostream>

using namespace std;

class A
{
public:
A() { cout << "A constructed \n"; }
~A() { cout << "~A desconstructed \n"; }
};

template<typename T>
unique_ptr<T> source( void )
{
	cout << "In source() \n" ;
	return unique_ptr<T>( new T );
}

template<typename T>
void sink( unique_ptr<T> p )
{
	cout << "In sink() \n" ;
}

void test( void )
{
  const unique_ptr<int[]> p(new int[3]);
  p[0] = 0;
  p[1] = 1;
  p[2] = 2;
	cout << p[0] << endl;
	cout << p[1] << endl;
	cout << p[2] << endl;
}

int main( int argc, char* argv[] )
{
	unique_ptr<A> pA = source<A>();
	pA.reset( new A );
	sink<A>( source<A>() );

	test();

	return 0;
}

